<?php

function save_data($title, $content, $fid, $uid, $is_aid){
 	
	$uid = rand(2, 15); //3-16可用UID
	$views = rand(200, 5000);

 	$time = time();
 	$author = mysql_fetch_array(mysql_query("select * from cdb_members WHERE uid = '$uid'"));
 	

    $cf_result = mysql_query("select * from cdb_threads WHERE subject = '$title'");//重复性
    if (mysql_num_rows($cf_result)) {
    	$msg = $title.'——重复文章跳过。。。<br/>';	
    }else{


	    //cdb_threads
		$sql = "INSERT INTO cdb_threads (fid, author, authorid, subject, dateline, lastpost, lastposter, views)
		VALUES ('$fid', '$author[username]', '$uid', '$title', '$time', '$time', '$author[username]', '$views')";
	    if (mysql_query($sql)) {
	    	$rs = mysql_fetch_array(mysql_query("select * from cdb_threads ORDER BY tid DESC"));
	    	$tid = $rs['tid'];

	    	//cdb_posts
	    	$post_sql = "INSERT INTO cdb_posts (fid, tid, first, author, authorid, subject, dateline, message, useip, smileyoff )
			VALUES ('$fid', '$tid', '1', '$author[username]', '$uid', '$title', '$time', '$content', '127.0.0.1', '-1')";

			if (mysql_query($post_sql)) {

				//pw_bbs_threads_index
		    	$sql = "INSERT INTO cdb_mythreads (uid, tid, dateline)
				VALUES ('$uid', '$tid', '$time')";
				mysql_query($sql);

				$lastpost = $tid."	".$title."	".$time."	".$author[username];
				//UPDATE pw_bbs_forum_statistics
				$sql = "UPDATE cdb_forums SET threads = threads+1, posts = posts+1, todayposts = todayposts+1, 
						lastpost = '$lastpost' WHERE fid = '$fid'";
				mysql_query($sql);



				$msg = "$title ---- 已成功发布!<br/>";
			}else{
				$msg = '连接出错 cdb_posts 表，未发布。跳过'.mysql_error()."<br/>";
			}

	    }else{
	    	$msg = '连接出错 cdb_threads 表，未发布。跳过'.mysql_error()."<br/>";
	    }

	}


	return $msg;
}